// xinwen.js
Page({
  data: {
    allNews: [],
    filteredNews: [],
    isLoading: true
  },

  onLoad() {
    this.loadNewsData();
  },

  loadNewsData() {
    // 从全局获取数据（需在app.js设置）
    const app = getApp();
    setTimeout(() => {
      this.setData({
        allNews: app.globalData.newsList,
        filteredNews: app.globalData.newsList,
        isLoading: false
      });
    }, 800);
  },

  onSearch(e) {
    const keyword = e.detail.value.toLowerCase();
    this.setData({
      filteredNews: this.data.allNews.filter(item => 
        item.title.toLowerCase().includes(keyword)
      )
    });
  },

  viewNewsDetail(e) {
    const id = e.currentTarget.dataset.id;
    wx.navigateTo({
      url: `/pages/news/detail?id=${id}`
    });
  }
});